﻿/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
/* -------------------------- Start ------------------------------------- */
/*PU ------------------------ Popup ------------------------------------- */
/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */

/* -------- sample---------------------------------------------------------	
popup(event, document.getElementById("reqMenu"), 'width:100;height:100;top:100;left:100;align:true;header:true');
popup(event, 'list_1.html', 'width:100;height:100;top:100;left:100;align:true;header:true');

<div class="fromCtr">
<input class="inputText userInput fromObj" type="text" id="" name="" value="" readonly="readonly" onclick="select_user_popup(event, this)" />
<input type="button" class="fromRemove" value="" onclick="CE.removeValue(this)"/>
</div>
-------------------------------------
features
	width
	height
	left
	top
	align
	header
	closebutton
	maxbutton
	resize
	border
	style
-------------------------------------
*/

var PU = {
	id : "PU",
	popups : new Array(),	
	topest : 3000,		//initial z-index of popup
	hdrHeight : 17,
	activePopUp : null,	
	isDragging : false,
	dragObj : null,		
	clickOnX : 0,
	clickOnY : 0,
	bdrW : 5,
	bdrH : 5,
	miniW : 50,
	miniH : 50,	
	wW : null,
	wH : null,
	disableAnimation : true,
	init : function(){
		if(typeof CG != "undefined"){
			CG.PU();
		}			
	/*
		var _popups = document.getElementsByTagName("popup");
		var _popupsAry = new Array();
		for(var i=0; i<_popups.length; i++){		
			_popupsAry.push(_popups[i]);
		}
		if(_popupsAry.length > 0){ // NO
			for(var k=0; k<_popupsAry.length; k++){		
				_popupsAry[k].k = k;
				this.popups[k] = new POPUP(_popupsAry[k]);
				this.activePopUp = PU.popups[k];
			}			
			//CE.addEventListener(document, "mousedown", this.mouseDown);
			//CE.addEventListener(document, "mouseup", this.mouseUp);
			//CE.addEventListener(document, "dblclick", this.doubleClick);	
		}
	*/
		CE.addEventListener(document, "mousedown", this.mouseDown);
		CE.addEventListener(document, "dblclick", this.dblclick);		
		CE.addEventListener(document, "mouseup", this.mouseUp);	
	},
/* ------------------------ (common + ) ------------------------ */	
/* ------------------------ (common + ) ------------------------ */	
/* ------------------------ (common + ) ------------------------ */
	doPopUp : function(tgt, from, to){
//		CE.alert(from.W +"__--__"+ to.W);
		var pop = PU.activePopUp;		
		var _u = pop.u;
		var _loadUrl = true;
		function doAction(){
			if(PU.disableAnimation){
				_tweenCompleted();
			}else{				
				doAnimation();

			}
		}
		function _tweenCompleted(){			
			tgt.style.visibility = "hidden";		
			pop.style.visibility = "visible";			
			PU.moveWinMask();
		}		
		function doAnimation(){
			tgt.style.visibility = "visible";
			//Tween(tgt, "alpha", Popup.easeOut, from.a, to.a, 15, false);
			//CE.alert(from.W +"____"+ to.W);
			Tween(tgt, "x", Popup.easeOut, from.X, to.X);
			Tween(tgt, "y", Popup.easeOut, from.Y, to.Y);
			Tween(tgt, "width", Popup.easeOut, from.W, to.W);
			var _tween = Tween(tgt, "height", Popup.easeOut, from.H, to.H);
			CE.copyPty(tgt, pop);			
			_tween.addEventListener("MOTION_FINISH", _tweenCompleted);			
		}
		//load html object to lower and remove the iframe in lower.
		if(typeof _u == "object"){
			_loadUrl = false;
			if(document.getElementById(_u.id + "_returnTarget") == undefined){
				var returnTarget = CE.newObj("div", _u.id + "_returnTarget", _u.id + "_returnTarget", "returnTarget", pop.k);
				_u.parentNode.insertBefore(returnTarget, _u);
			}else{
				var returnTarget = document.getElementById(_u.id + "_returnTarget");
			}
			_u.initDisplay = _u.style.display;
			_u.style.display = "";
			PU.activePopUp.returnTarget = returnTarget;
			PU.activePopUp.returnObject = _u;
			pop.lower.appendChild(_u); 
			doAction();
		}	
		if(_loadUrl){
			pop.urlFrame.src = pop.urlFrame.u;
			pop.urlFrame.loadedByUserAction = false;
			CE.onReadyStateChange(pop.urlFrame, doAction);
/*			

			pop.urlFrame.onreadystatechange =function(){  
				if(pop.urlFrame.readyState){
					if(pop.urlFrame.readyState=="complete"){
						//alert("onreadystatechange_loaded")
						doAction();
					}
				}else{
					//alert("FF onreadystatechange_loaded");
					doAction();
				}
			}
			if (!CE.browser("IE")){ 
				pop.urlFrame.onload =function(){  
					this.onreadystatechange.apply(this);
				}
			}
*/
		} 
	},
	topestPopUpZIndex : function(){
		var pu = PU.popups;
		var zIndex = 0;
		for(var i=0; i<pu.length; i++){
			if(typeof pu[i] == "object"){
				if(pu[i].style.zIndex > zIndex)
					zIndex = pu[i].style.zIndex;
			}
		}
		//CE.alert(zIndex);
		return zIndex;
	},
	moveWinMask : function(){
		//move mask below topest popup
		var topestZIndex = PU.topestPopUpZIndex();
		if(topestZIndex != 0 ){
			CE.winMask().toZIndex(topestZIndex-1);
			CE.winMask().on();
		}else{
			CE.winMask().off();
		}
	},
/* ------------------------ (common - ) ------------------------ */	
/* ------------------------ (common - ) ------------------------ */	
/* ------------------------ (common - ) ------------------------ */	
	syncPty : function(a, b){
		a.style.left = b.style.left;		
		a.style.top = b.style.top;
		a.style.width = b.style.width;
		a.style.height = b.style.height;
		a.X = parseInt(b.style.left);
		a.Y = parseInt(b.style.top);
		a.W = parseInt(b.style.width);
		a.H = parseInt(b.style.height);
	},
	moveToTop : function(_ctr){
		this.topest++;
		_ctr.style.zIndex = this.topest;
	},
	dblclick : function(e){
		var thisObj = CE.eventObj(e);		
		if(!thisObj) return;		
		if (!thisObj.draggable) return;		
		PU.activePopUp = PU.popups[thisObj.k];
		PU.moveToTop(PU.activePopUp);		
		if( PU.RESIZE){
			if(PU.activePopUp.RESIZE){			
				if(thisObj.id == "upper"){
					if(PU.activePopUp.sizeBtn.id == "restoreBtn"){
						PU.restore(PU.activePopUp);
					}else if(PU.activePopUp.sizeBtn.id == "maxiBtn"){
						PU.maximize(PU.activePopUp);
					}
				}
			}
		}
	},
	mouseDown : function(e){
		var thisObj = CE.eventObj(e);		
		if(!thisObj) return ;		
		if (!thisObj.draggable) return;		
		if(thisObj.id.match(/upper/)){
			PU.isDragging = true;
			// move to top
			PU.activePopUp = PU.popups[thisObj.k];
			PU.moveToTop(PU.activePopUp);
			//add drag event handle
			var dmy = CE.aniBox();
			dmy.style.visibility = "visible";
			PU.syncPty(dmy, PU.activePopUp);
			PU.dragObj = dmy;
			PU.dragObj.style.cursor = "move";
			PU.dragObj.key = "upper";
			PU.clickOnX = e.clientX - PU.dragObj.X;
			PU.clickOnY = e.clientY - PU.dragObj.Y;
			CE.addEventListener(document, "mousemove", PU.mouseMove);			
			CE.winMask().on();
			CE.winMask().toTop();
		}
		if(thisObj.id.match(/closeBtn/)){
			
			//--------- remove the div and iframe----------START
			$(".aniBox").remove();
			$(".winMask").remove();
			$(".popup").remove();			
			//--------- remove the div and iframe----------END
			
			/* Modify by lj
			if(!CE.browser("IE")){	
				e.preventDefault();		
			}else{
				e.returnValue = false;				
			}
			PU.closePopUp(thisObj.k);	
			*/	
			
		}else if(thisObj.id.match(/maxiBtn/) && PU.RESIZE ){			
			if(!CE.browser("IE")){	
				e.preventDefault();		
			}else{
				e.returnValue = false;				
			}
			PU.activePopUp = PU.popups[thisObj.k];
			PU.moveToTop(PU.activePopUp);			
			PU.maximize(PU.activePopUp);
		}else if(thisObj.id.match(/restoreBtn/)){
			if(!CE.browser("IE")){	
				e.preventDefault();		
			}else{
				e.returnValue = false;				
			}
			PU.activePopUp = PU.popups[thisObj.k];
			PU.restore(PU.activePopUp);			
		}
		/* ------------------------------- resize ------------------------------- */
		if(thisObj.name.match(/resizeHandle/) && PU.RESIZE){
			PU.activePopUp = PU.popups[thisObj.k];			
			if(PU.activePopUp.RESIZE){
				PU.isDragging = true;
				PU.activePopUp = PU.popups[thisObj.k];
				var dmy = CE.aniBox();
				dmy.style.visibility = "visible";
				PU.syncPty(dmy, PU.activePopUp);
				PU.dragObj = dmy;
				PU.dragObj.style.cursor = "move";
				PU.dragObj.key = "resizeHandle_" + thisObj.id;
				CE.winMask().on();
				CE.winMask().toTop();
				CE.addEventListener(document, "mousemove", PU.mouseMove);
			}
		}
		/* ------------------------------- resize ------------------------------- */
		return false;
	},	
	mouseUp : function(e){
		if (!e) e = window.event;
		if (e.button > 1) return true;
		if (!e.target) e.target = e.srcElement;		
		var thisObj = e.target;			
		if(PU.isDragging){
			PU.dragObj.style.visibility = "hidden";
			PU.dragObj.style.cursor = "default";			
			PU.syncPty(PU.activePopUp, PU.dragObj);
			if(PU.dragObj.key == "upper"){

			}else if( PU.dragObj.key.match(/resizeHandle/) && PU.RESIZE ){
				CE.setPty(PU.activePopUp);
				PU.resize(PU.activePopUp);
			}
			PU.activePopUp.style.visibility = "visible";			
//			CE.winMask().off();
//			CE.winMask().toBottom();
			PU.moveWinMask();
		}		
		CE.removeEventListener(document, "mousemove", PU.mouseMove);
		PU.isDragging = false;
		PU.dragObj = null;
		return false;		
	},	
	mouseMove : function(e){
		if (!e) e = window.event;
		if (e.button > 1) return true;
		if (!e.target) e.target = e.srcElement;		
		var thisObj = e.target;
		if (!PU.dragObj) return;	
		if(PU.isDragging){
			if(PU.dragObj.key == "upper"){
				//drag to move the popup
				PU.dragObj.style.left = e.clientX - PU.clickOnX + "px";
				PU.dragObj.style.top = e.clientY - PU.clickOnY + "px";
			}else if(PU.dragObj.key.match(/resizeHandle/)){
				CE.pty(PU.activePopUp);
				switch(PU.dragObj.key.replace("resizeHandle_", "")){
					case "c21":	
						//pAA
						if((PU.activePopUp.X + PU.activePopUp.W) - e.clientX >= PU.miniW){
							PU.dragObj.style.left = e.clientX + "px";
							PU.dragObj.style.width = (PU.activePopUp.X + PU.activePopUp.W) - e.clientX + "px";
						}else{
							PU.dragObj.style.left = (PU.activePopUp.X + PU.activePopUp.W) - PU.miniW + "px";
							PU.dragObj.style.width = PU.miniW + "px";
						}
						break;
					case "c12":	
						//pBB
						if((PU.activePopUp.Y + PU.activePopUp.H) - e.clientY >= PU.miniH){
							PU.dragObj.style.top = e.clientY + "px";					
							PU.dragObj.style.height = (PU.activePopUp.Y + PU.activePopUp.H) - e.clientY + "px";
						}else{
							PU.dragObj.style.top = (PU.activePopUp.Y + PU.activePopUp.H) - PU.miniH + "px";				
							PU.dragObj.style.height = PU.miniH + "px";
						}
						break;						
					case "c32":	
						//DD
						if(e.clientY - PU.activePopUp.Y >= PU.miniH){
							PU.dragObj.style.height = e.clientY - PU.activePopUp.Y + "px";
						}else{
							PU.dragObj.style.height = PU.miniH + "px";
						}
						break;
					case "c23":	
						//CC
						if(e.clientX - PU.activePopUp.X >= PU.miniW){
							PU.dragObj.style.width = e.clientX - PU.activePopUp.X + "px";
						}else{
							PU.dragObj.style.width = PU.miniW + "px";
						}
						break;
					case "c11":	
						//pAA
						if((PU.activePopUp.X + PU.activePopUp.W) - e.clientX >= PU.miniW){
							PU.dragObj.style.left = e.clientX + "px";
							PU.dragObj.style.width = (PU.activePopUp.X + PU.activePopUp.W) - e.clientX + "px";
						}else{
							PU.dragObj.style.left = (PU.activePopUp.X + PU.activePopUp.W) - PU.miniW + "px";
							PU.dragObj.style.width = PU.miniW + "px";
						}
						//pBB
						if((PU.activePopUp.Y + PU.activePopUp.H) - e.clientY >= PU.miniH){
							PU.dragObj.style.top = e.clientY + "px";					
							PU.dragObj.style.height = (PU.activePopUp.Y + PU.activePopUp.H) - e.clientY + "px";
						}else{
							PU.dragObj.style.top = (PU.activePopUp.Y + PU.activePopUp.H) - PU.miniH + "px";				
							PU.dragObj.style.height = PU.miniH + "px";
						}
						break;
					case "c31":	
						//DD
						if(e.clientY - PU.activePopUp.Y >= PU.miniH){
							PU.dragObj.style.height = e.clientY - PU.activePopUp.Y + "px";
						}else{
							PU.dragObj.style.height =  PU.miniH + "px";
						}
						//AA
						if((PU.activePopUp.X + PU.activePopUp.W) - e.clientX >= PU.miniW){
							PU.dragObj.style.left = e.clientX + "px";
							PU.dragObj.style.width = (PU.activePopUp.X + PU.activePopUp.W) - e.clientX + "px";
						}else{
							PU.dragObj.style.left = (PU.activePopUp.X + PU.activePopUp.W) - PU.miniW + "px";
							PU.dragObj.style.width = PU.miniW + "px";
						}
						break;
					case "c13":	
						//CC
						if(e.clientX - PU.activePopUp.X >= PU.miniW){
							PU.dragObj.style.width = e.clientX - PU.activePopUp.X + "px";
						}else{
							PU.dragObj.style.width = PU.miniW + "px";
						}						
						//pBB
						if((PU.activePopUp.Y + PU.activePopUp.H) - e.clientY >= PU.miniH){
							PU.dragObj.style.top = e.clientY + "px";					
							PU.dragObj.style.height = (PU.activePopUp.Y + PU.activePopUp.H) - e.clientY + "px";
						}else{
							PU.dragObj.style.top = (PU.activePopUp.Y + PU.activePopUp.H) - PU.miniH + "px";				
							PU.dragObj.style.height = PU.miniH + "px";
						}
						break;
					case "c33":	
						//CC
						if(e.clientX - PU.activePopUp.X >= PU.miniW){
							PU.dragObj.style.width = e.clientX - PU.activePopUp.X + "px";
						}else{
							PU.dragObj.style.width = PU.miniW + "px";
						}
						//DD
						if(e.clientY - PU.activePopUp.Y >= PU.miniH){
							PU.dragObj.style.height = e.clientY - PU.activePopUp.Y + "px";
						}else{
							PU.dragObj.style.height =  PU.miniH + "px";
						}
						break;						
					default:
						CE.alert("no resizeHandle mouseMove");
				}
			}
		}
		return false;
	},	
	move : function(ctr){
		ctr.style.top = ctr.Y + "px";
		ctr.style.left = ctr.X + "px";
	},
	resize : function(ctr){
		var _hdrH = (ctr.HEADER) ? this.hdrHeight : 0;
		var _bdrW = 2*this.bdrW;
		var _bdrH = 2*this.bdrH;		
		ctr.style.width = ctr.W + "px";		
		ctr.style.height = ctr.H  + "px";
		ctr.bdr.style.width = ctr.W - _bdrW + "px";
		ctr.bdr.style.height = ctr.H - _bdrH + "px";		
		ctr.upper.style.width = ctr.W - _bdrW + "px";
		ctr.upper.style.height = _hdrH + "px";		
		ctr.lower.style.height = ctr.H - _hdrH - _bdrH + "px";
		ctr.lower.style.width = ctr.W - _bdrW + "px";
		if(ctr.urlFrame){
			ctr.urlFrame.style.height = ctr.H - _hdrH - _bdrH + "px";		
			ctr.urlFrame.style.width = ctr.W - _bdrW + "px";
		}
		if(CE.browser("IE6")){
			ctr.mask.style.width = ctr.W + "px";
			ctr.mask.style.height = ctr.H + "px";		
		}
	},
	alignToThis : function(_this, popW, popH, pageW, pageH){
		var pPos = new Object();
		pPos.X = _this.X - popW + _this.W;
		if(pPos.X < 0){
			pPos.X = _this.X;
		}		
		pPos.Y = _this.Y + _this.H;
		if((pPos.Y + popH) >  pageH){
			pPos.Y = _this.Y - popH;
		}
		return pPos;
	},
	removeValueFromObject : function(thisObj){ 	
		var _ctr = thisObj.parentNode;
		var _input = CE.$s(_ctr, "input")[0];
		_input.value = "";
	},	
	returnValueToFromObject : function(_k, _value){ 	
		PU.activePopUp = PU.popups[_k];
		var _ctr = PU.activePopUp;		
		_ctr.fromObj.value = _value;
	},	
	closePopUp : function(_k){		
		function finishFunction(){
			aniBox.style.visibility = "hidden";
		}		
		PU.activePopUp = PU.popups[_k];
		var _ctr = PU.activePopUp;
 		
		if(PU.disableAnimation){
			
		}else{
			var aniBox = document.getElementById("aniBox");
			aniBox.style.visibility = "visible";	
			CE.copyPty(_ctr, aniBox);	
			// from pty to anibox for backward animation
			// CE.alertPty(_ctr);
			CE.setPty(aniBox, [_ctr.X, _ctr.Y, _ctr.W, _ctr.H], [_ctr.fromX, _ctr.fromY, _ctr.fromW, _ctr.fromH]);
	
			AN.backward(aniBox, Popup.easeOut, 20, finishFunction);
		}
		if(PU.activePopUp.returnObject != undefined){
			//CE.alert(PU.activePopUp.returnObject.initDisplay);
			PU.activePopUp.returnObject.style.display = PU.activePopUp.returnObject.initDisplay; 
			PU.activePopUp.returnTarget.appendChild(PU.activePopUp.returnObject);
		}
		// remove the popup
		// can't use it, error on ie, input field will disabled after reopen the window
		//document.body.removeChild(PU.popups[_k]);
		
		PU.popups[_k].style.display = "none";
		PU.popups[_k] = _k + ".) ==> closed";						
		PU.moveWinMask();
	},
	restore : function(_ctr){
		PU.moveToTop(_ctr);		
		_ctr.style.visibility = "hidden";
		var aniBox = document.getElementById("aniBox");		
		
		function finishFunction(){
			if(PU.disableAnimation){			
//				CE.alertPty(_ctr);
				CE.setPty(_ctr, [_ctr.preX, _ctr.preY, _ctr.preW, _ctr.preH]);
			}else{
				CE.copyPty(aniBox, _ctr);
			}
			PU.move(_ctr);
			PU.resize(_ctr);			
			aniBox.style.visibility = "hidden";
			_ctr.style.visibility = "visible";
		}		

		if(PU.disableAnimation){
			finishFunction();
		}else{
			CE.copyPty(_ctr, aniBox);
			aniBox.style.visibility = "visible";
			AN.backward(aniBox, Popup.easeOut, 20, finishFunction);			
		}
		_ctr.sizeBtn.id = "maxiBtn";
		_ctr.sizeBtn.className = "maxiBtn";			
	},	
	maximize : function(_ctr){
		_ctr.style.visibility = "hidden";
		this.wW = CE.docPty().W;
		this.wH = CE.docPty().H;
		var _pX = 0;
		var _pY = 0;
		var _pW = this.wW - 2;
		var _pH = this.wH - 2;
		CE.pty(_ctr);
		var aniBox = document.getElementById("aniBox");	
		CE.copyPty(_ctr, aniBox);
		//obj, cur, pre, from
//		CE.setPty(_ctr, [_pX, _pY, _pW, _pH], [_ctr.X, _ctr.Y, _ctr.W, _ctr.H], [_ctr.X, _ctr.Y, _ctr.W, _ctr.H]);		
		CE.setPty(_ctr, [_pX, _pY, _pW, _pH], [_ctr.X, _ctr.Y, _ctr.W, _ctr.H]);		
//		CE.alertPty(_ctr);
		this.move(_ctr);
		this.resize(_ctr);
		this.doPopUp(aniBox, aniBox, _ctr);
		_ctr.sizeBtn.id = "restoreBtn";
		_ctr.sizeBtn.className = "restoreBtn";		
	},
	animation : function(e, ctr){
		_btn = CE.eventObj(e);
		if(!_btn) return;
		
		CE.pty(_btn);
		
		var aniBox = CE.aniBox();
		aniBox.style.visibility = "hidden";
		aniBox.style.left = _btn.X + "px";
		aniBox.style.top = _btn.Y + "px";
		aniBox.style.width = _btn.W + "px";
		aniBox.style.height = _btn.H + "px";
		
		var _win = CE.docPty(); //w = window
		var _pW = ctr.W; // p = popup
		var _pH = ctr.H;		

		if(ctr.ALIGN){
			//var _pPos = this.alignToThis(_btn, _pW + 2*this.bdrW, _pH + 2*this.bdrH, _wW, _wH);
			var _pPos = this.alignToThis(_btn, _pW, _pH, _win.W, _win.H);
			_pX = _pPos.X;
			_pY = _pPos.Y;
		}else{		
			var _pX = (ctr.X == 0) ? parseInt((_win.W-_pW)/2)+_win.sL : parseInt(ctr.X);	
			//specify location, if no, align to center
			if(_pX < 0 ) _pX = 0;
			var _pY = (ctr.Y == 0) ? parseInt((_win.H-_pH)/2)+_win.sT : parseInt(ctr.Y); 	
			//specify location, if no, align to middle
			if(_pY < 0 ) _pY = 0;
		}
		if(ctr.H == this.miniH){
			//not specify height and width
			this.maximize(ctr);
		}else{
			CE.setPty(ctr, [_pX, _pY, _pW, _pH], [_btn.X, _btn.Y, _btn.W, _btn.H]); 
			// popup, pmr of popup, pmr of event object.
			this.move(ctr);
			this.resize(ctr);
			CE.pty(ctr);
			this.doPopUp(aniBox, _btn, ctr);
		}
	},
	addBdr : function(bdr){
		var _bdrTbe = CE.newObj("table", "dragBdr", "dragBdr", "dragBdr", bdr.k);
		_bdrTbe.border = 0;
		_bdrTbe.width = "100%"; 
		_bdrTbe.cellPadding = 0; 
		_bdrTbe.cellSpacing = 0;
		_bdrTbe.style.position = "absolute";
		var _ID = "";
		for(var i=0; i<3; i++){
			_bdrTbe.insertRow(-1);
			for(var j=0; j<3; j++){
				_ID = "c" + (i+1) + (j+1); // c11, c12, c13,....
				_bdrTbe.rows[i].insertCell(-1);
				var _cell = _bdrTbe.rows[i].cells[j];
				if(!(i==1 && j==1)){ //except, c22
					_cell.k = bdr.k;
					_cell.id = _ID;
					_cell.className = _ID;					
					_cell.draggable = true;					
					_cell.name = "resizeHandle";
					if(!bdr.RESIZE){
						//if(!PU.RESIZE){
							_cell.style.cursor = "default";
						//}
					}
				}
				if(i!=1 && j!=1){ // 4 corner, assign width
					_cell.style.width = this.bdrW + "px";
					_cell.style.height = this.bdrH + "px";
				}
			}
		}
		_bdrTbe.rows[1].cells[1].appendChild(bdr);
		return _bdrTbe;
	},
	ALIGN : false,
	HEADER : true,
	CLOSE : true,
	MAXIMIZE : false,
	RESIZE : false,
	BORDER : true,
	STYLE : "",	
	popup : function(args){		
		var _e = _u = _w = _h = _x = _y = _k = _z = _f = features = pmr = null;		
		var _align = _header = _close = _maximize = _resize = _border = _style = null;		
		_e = (args[0] == undefined) ? "" : args[0];	//event
		_u = (args[1] == undefined) ? "" : args[1];	//url
		_w = this.miniW;
		_h = this.miniH;
		_x = 0;
		_y = 0;
		this.wW =  CE.docPty().W;
		this.wH =  CE.docPty().H;
		
		if(args.length == 3){
/*---------------------------------------------------------------------*/
		if(args[2] != undefined){
			features = args[2].toString().toLowerCase().split(";");
			for(var i=0; i<features.length; i++){
				pmr = features[i].split(":");
				switch(pmr[0]){
					case "width":
						_w = pmr[1];					
						break;
					case "height":
						_h = pmr[1];
						break;
					case "left":
						_x = pmr[1];
						break;
					case "top":
						_y = pmr[1];
						break;
					case "align":
						_align = eval(pmr[1]);
						break;
					case "header":
						_header = eval(pmr[1]);
						break;
					case "closebutton":
						_close = eval(pmr[1]);
						break;
					case "maxbutton":
						_maximize = eval(pmr[1]);
						break;
					case "resize":
						_resize = eval(pmr[1]);
						break;
					case "border":
						_border = eval(pmr[1]);
						break;
					case "style":
						_style = " " + pmr[1];
						break;
					default:						
				}
			}
		}
/*---------------------------------------------------------------------*/
		}else if(args.length > 3){
/*---------------------------------------------------------------------*/
			_w = args[2];
			_h = args[3];
			if(args.length == 6){
				_x = args[4];
				_y = args[5];
			}else if(args.length == 5){
				if(args[4] == "alignToThis"){
					_align = true;
				}
			}else if(args.length == 4){
				 
			}
/*---------------------------------------------------------------------*/
		}
		_k = this.popups.length;		
		_z = this.topest;
		_f = CE.eventObj(_e);	//from object.

		if(_align == null)		
			_align = this.ALIGN;
		if(_header == null)		
			_header = this.HEADER;
		if(_close == null)		
			_close = this.CLOSE;
		if(_maximize == null)		
			_maximize = this.MAXIMIZE;
		if(_resize == null)		
			_resize = this.RESIZE; 
		if(_border == null)		
			_border = this.BORDER;
		if(_style == null)		
			_style = this.STYLE;

		this.topest++;		
		var _ctr = CE.newObj("div", "popup_"+_k+"_", "popup_"+_k+"_", "popup" + _style , _k);
		_ctr.style.zIndex = _z;				
		_ctr.ALIGN = _align;
		_ctr.CLOSE = _close;
		_ctr.MAXIMIZE = _maximize;		
		_ctr.HEADER = _header;
		_ctr.RESIZE = _resize;


		document.body.appendChild(_ctr);
		
		var _closeBtn = CE.newObj("div", "closeBtn", "closeBtn", "closeBtn", _k);
		_closeBtn.draggable = true;
		_closeBtn.style.display = (_close) ? "" : "none";
 		
		var _maxiBtn = CE.newObj("div", "maxiBtn", "maxiBtn", "maxiBtn", _k);
		_maxiBtn.draggable = true;
		_maxiBtn.style.display = (_maximize) ? "" : "none";
		
		var _upper = CE.newObj("div", "upper", "upper", "upper", _k);
		_upper.draggable = true;
		_upper.style.display = (_header) ? "" : "none";

		var _lower = CE.newObj("div", "lower", "lower", "lower", _k);
		var _bdr = CE.newObj("div", "border", "border", "border", _k);
		_bdr.RESIZE = _resize;
		
		if(CE.browser("IE6")){
			var _mask = CE.newObj("iframe", "mask", "mask", "mask", _k);
			_mask.src = "about:blank";
			_ctr.appendChild(_mask);
		}
		_upper.appendChild(_closeBtn);
		_upper.appendChild(_maxiBtn);

			
/* - Iframe  --------------------------------------------- */		
		if(typeof _u == "object"){
			_ctr.u = _u;
		}else{
			var _urlFrame = CE.newObj("iframe", "urlFrame", "urlFrame", "urlFrame", _k);	
			_urlFrame.u = (_u == "") ? "about:blank" : _u;
			_lower.appendChild(_urlFrame);
			_ctr.urlFrame = _urlFrame;
		}
	
		_bdr.appendChild(_upper);
		_bdr.appendChild(_lower);
		_ctr.mask = _mask;
		_ctr.upper = _upper;
		_ctr.lower = _lower;
		_ctr.bdr = _bdr;
		_ctr.closeBtn = _closeBtn;		
		_ctr.sizeBtn = _maxiBtn;
		
		if(_border){
			var _newbdr = this.addBdr(_bdr);			
			_ctr.appendChild(_newbdr);			
		}else{
			_ctr.appendChild(_bdr);
		}
		
		var _btn = CE.eventObj(_e);
		if(!_btn) return;
		
		CE.pty(_btn);
	
		CE.setPty(_ctr, [_x, _y, _w, _h], [_btn.X, _btn.Y, _btn.W, _btn.H], [_btn.X, _btn.Y, _btn.W, _btn.H]);
		
		_ctr.fromObj = _f;
//		this.popups[_k] = new POPUP(_ctr);
		this.popups[_k] = _ctr;
		this.activePopUp = _ctr;
		this.animation(_e, _ctr); 
	} 
}
POPUP = function(pup){
	return pup;
}
function popup(){
	var args = arguments;	
	var e = args[0];
	PU.popup(args);
}

//PU.init();
 
/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
/* -------------------------- End --------------------------------------- */
/* -------------------------- Popup ------------------------------------- */
/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */

